package com.siwen.controller;


import com.siwen.mapper.QuotaresultMapper;
import com.siwen.pojo.QuotaresultTbl;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
public class QuotaresultController {
    @Resource
    private QuotaresultMapper quotaresultMapper;

    /**
     * 根据id查询
     * @param childid
     * @return
     */
    @RequestMapping("/getQuoResult")
    public List<QuotaresultTbl> queryAll(@RequestParam("childid") int childid){
        List<QuotaresultTbl> quotaresultTbls = quotaresultMapper.selectAll(childid);
        return quotaresultTbls;
    }

    /**
     * 查询所有
     * @return
     */
    @RequestMapping("/getAll")
    public List<QuotaresultTbl> queryQutoa(){
        List<QuotaresultTbl> quotaresultTbls = quotaresultMapper.selectChildQuota();
        return quotaresultTbls;
    }

    /**
     * 添加
     * @param q
     * @return
     */
    @RequestMapping("/addQutoa")
    public int addQutoa(QuotaresultTbl q){
            q.setQuotaid(4);
            q.setPlanexecuteid(4);
            q.setChildid(4);
            q.setCheckesult("好");
            q.setCheckdate(new Date());
            q.setDescribe("好");
            int result=quotaresultMapper.insertQutoa(q);
            if(result>0){
                System.out.println("添加成功");
            }else{
                System.out.println("添加失败");
            }
            return result;
    }

    /**
     * 删除
     * @param childid
     * @return
     */
    @RequestMapping("/deletqutoa")
    public int delete(int childid ){
        int result=quotaresultMapper.deleteQuto(childid);
        if (result>0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
        return result;
    }

}
